﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibraryChat;

namespace ChatClient
{
    public partial class _Default : System.Web.UI.Page
    {
        private void FillChannels()
        {
            foreach (var item in DBManipulation.GetAllChannels())
            {
                listBoxChannels.Items.Add("#" + item.Key);
            }
        }

        private void FillUsers()
        {
            foreach (var item in DBManipulation.GetAllUsers())
            {
                listBoxUsers.Items.Add("@" + item.Key);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillChannels();
                FillUsers();
            }
            List<Message> messages = DBManipulation.GetMessagesByChannel("");
        }

        protected void listBoxChannels_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxChannels.SelectedItem == null)
            {
                return;
            }
            string channel = listBoxChannels.SelectedItem.Text;
            DBManipulation.GetMessagesByChannel(channel);
        }
    }
}
